#include "./vulkanRenderer/std.hpp"

#if defined(WIN32)
int WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pCmdLine, int nCmdShow) {
#elif defined(__linux__)
int main(int argc,char** argv){
#endif //

	Vulkan::DeviceInit::init();

	static Vulkan::Scene scene;
	scene.init();

	auto scrollCallback = [](GLFWwindow*, double, double wheelDelta) {
		scene.camera.zoom += (float)wheelDelta * 0.1f;
		scene.camera.update();
	};

	static bool mouseDown = false;
	static int mouseButton = 0;
	static double x, y;
	auto mouseCallback = [](GLFWwindow* window, int button, int action, int mods) {
		if (action == GLFW_PRESS) {
			glfwGetCursorPos(window, &x, &y);
			mouseButton = button;
			mouseDown = true;
		}
		else if (action == GLFW_RELEASE) {
			mouseDown = false;
		}
	};

	auto cursorPosCallback = [](GLFWwindow* window, double curX, double curY) {
		if (mouseDown) {
			if (mouseButton == GLFW_MOUSE_BUTTON_RIGHT)
			{
				scene.camera.zoom += ((float)y - (float)curY) * 0.05f;
			}
			if (mouseButton == GLFW_MOUSE_BUTTON_LEFT)
			{
				scene.camera.rotation.x += ((float)y - (float)curY) * 1.25f;
				scene.camera.rotation.y -= ((float)x - (float)curX) * 1.25f;
			}
			if (mouseButton == GLFW_MOUSE_BUTTON_MIDDLE)
			{
				scene.camera.position.x -= ((float)x - (float)curX) * 0.01f;
				scene.camera.position.y -= ((float)y - (float)curY) * 0.01f;
			}
			x = curX;
			y = curY;
			scene.camera.update();
		}
	};

	glfwSetScrollCallback(Vulkan::context.window, scrollCallback);
	glfwSetMouseButtonCallback(Vulkan::context.window, mouseCallback);
	glfwSetCursorPosCallback(Vulkan::context.window, cursorPosCallback);

	while (!glfwWindowShouldClose(Vulkan::context.window))
	{
		glfwPollEvents();
		scene.draw();
	}

	return 0;
}
